package com.sinosoft.jwjw.component.controller.clueManage;


import javax.servlet.http.HttpServletRequest;

import com.sinosoft.jwjw.utils.ResultList;
import com.sinosoft.jwjw.utils.ResultPage;
import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.sinosoft.jwjw.base.BaseCrudController;
import com.sinosoft.jwjw.base.BaseCrudService;
import com.sinosoft.jwjw.component.model.clueManage.ClueBasicInfo;
import com.sinosoft.jwjw.component.model.clueManage.ClueInvolvedPersonInfo;
import com.sinosoft.jwjw.component.service.clueManage.ClueBasicInfoService;
import com.sinosoft.jwjw.component.service.clueManage.ClueInvolvedPersonService;
import com.sinosoft.jwjw.utils.ConvertUtil;
import com.sinosoft.jwjw.utils.ResultDetail;

/**
 * 线索基本信息控制层
 *
 * @ver 系统自动生成代码
 */
@Controller
@RequestMapping(value = "/culeBasic")
public class ClueBasicInfoController extends BaseCrudController<ClueBasicInfo, String> {

	@Autowired
	private ClueBasicInfoService clueBasicInfoService;

	@Autowired
	private ClueInvolvedPersonService clueInvolvedPersonService;

	@Override
	public BaseCrudService<ClueBasicInfo, String> getBaseService() {
		return clueBasicInfoService;
	}

	@ResponseBody
	@RequestMapping(value = "/saveClue", method = RequestMethod.GET)
	public ResultDetail saveClue(HttpServletRequest request) {
		//获取参数
		RequestParamUtils();
		//返回结果参数
		ResultDetail result = new ResultDetail();
		//解析处理参数
		JSONObject clueBasicJson = (JSONObject) params.get("clueBasicInfo");
		JSONObject clueInvolvedPersonJson = (JSONObject) params.get("clueInvolvedPersonInfo");
		String id = ConvertUtil.toString(clueBasicJson.get("id"));
		ClueBasicInfo clueBasicInfo = new ClueBasicInfo();//线索基本信息
		ClueInvolvedPersonInfo clueInvolvedPersonInfo = new ClueInvolvedPersonInfo();//涉案人员信息
		if (id == null || "".equals(id)) {
			id = ConvertUtil.getUUID20();
			clueBasicInfo = ConvertUtil.toObject(clueBasicJson.toString(), ClueBasicInfo.class);
			clueInvolvedPersonInfo = ConvertUtil.toObject(clueInvolvedPersonJson.toString(), ClueInvolvedPersonInfo.class);
			clueBasicInfo.setId(id);
			clueInvolvedPersonInfo.setId(id);
		}
		int flag = clueBasicInfoService.saveCule(clueBasicInfo);
		result.setCode(flag);
		return result;
	}

	/**
	 * 分页查询线索基本信息列表
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/querylist")
	public String querylist(HttpServletRequest request) {
		//整装参数
		RequestParamUtils();
		//解析处理参数
		String currentActiveNo = ConvertUtil.toString(params.get("currentActiveNo"));
		String acceptDateStartTime = ConvertUtil.toString(params.get("acceptDateStartTime"));//yyyy-MM-dd HH:mm:ss
		String acceptDateEndTime = ConvertUtil.toString(params.get("acceptDateEndTime"));//yyyy-MM-dd HH:mm:ss
		String clueNo = ConvertUtil.toString(params.get("clueNo"));
		String clueName = ConvertUtil.toString(params.get("clueName"));
		String clueSourceCode = ConvertUtil.toString(params.get("clueSourceCode"));
		ResultPage resultPage = clueBasicInfoService.getListPage(pageIndex, pageSize, currentActiveNo, acceptDateStartTime, acceptDateEndTime, clueNo, clueName, clueSourceCode);
		return resultPage.toString();
	}

	/**
	 * 线索受理按来源分组统计已处置未处置量
	 *
	 * @param request
	 * @return
	 */
	@ResponseBody
	@RequestMapping(value = "/countBySource")
	public String countBySource(HttpServletRequest request) {
		//获取参数
		RequestParamUtils();
		//受理时间起止
		String acceptDateStartTime = ConvertUtil.toString(params.get("acceptDateStartTime"));//yyyy-MM-dd HH:mm:ss
		String acceptDateEndTime = ConvertUtil.toString(params.get("acceptDateEndTime"));//yyyy-MM-dd HH:mm:ss
		ResultList result = clueBasicInfoService.countBySource(acceptDateStartTime, acceptDateEndTime);
		return result.toString();
	}
}
